package cn.hn3l.agriculture.controllers;

import cn.hn3l.agriculture.dao.mapper.QuestionPaperMapper;
import cn.hn3l.agriculture.entitis.QuestionPaper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jly on 2016/12/28.
 */
@Controller
@RequestMapping("/paper")
public class ExamController {
    @Resource
    private QuestionPaperMapper questionPaperMapper;

    @RequestMapping("questionList")
    public String examQuestion(Model model){
        List<QuestionPaper> chooseList = questionPaperMapper.choose();
        List<QuestionPaper> judgeList = questionPaperMapper.judge();
        Map<String,String> choose = new HashMap<>();
        Map<String,String> judge = new HashMap<>();
        int i = 1;
        int j = 1;
        for (QuestionPaper question:chooseList
             ) {
            String c = question.getQuestion() + ";";
            String a = question.getAnswer();
            choose.put("question" + i,c + a);
            i=i+1;
        }
        for (QuestionPaper question:judgeList
                ) {
            String c = question.getQuestion() + ";";
            String a = question.getAnswer();
               judge.put("question" + j,c + a);
            j = j+1;
        }
        model.addAttribute("chooseMap",choose);
        model.addAttribute("judgeMap",judge);
        return "questionpaper";
    }
}
